package com.label.Scheduled;

import com.label.Service.PersonsService;
import com.label.Utils.HdfsFileUtil;
import com.label.Utils.MailUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@EnableScheduling
@Service
@RestController
public class Task {

    private static final Logger log = LoggerFactory.getLogger(Task.class);

    @Autowired
    @Qualifier("sparkSqlJdbcTemplate")
    private JdbcTemplate sparkJdbc;

    @Resource
    private PersonsService personsService;

    @Scheduled(cron = "0 0 1 * * ?")
    public void test() throws IOException{
        log.info("springtask 定时任务！");
        log.info(new Date().toString());
//        tests();
    }

    @Scheduled(cron = "0 0/5 * * * ? ")
    public void checkDataBase() {
        log.info("定时任务");
        try{
            sparkJdbc.execute("select 1");
        }catch (Exception e){
            log.error("未知错误");
            MailUtil.sendAlertMessage();
        }
    }





}
